/* jshint esversion: 6 */
import axios from 'axios';
import store from '../vuex';
const baseURL = process.env.NODE_ENV === 'development' ? 'https://www.easy-mock.com/mock/5b8f904cf9900e4a46af769e' : '';
const xzName = process.env.NODE_ENV === 'development' ? '' : '/xz';
const Qs = require('qs');

axios.interceptors.request.use(
  config => {
	let token = store.state.user.token;
	if (token) { // 每次发送请求之前判断是否存在token，如果存在，则统一在http请求的header都加上token，不用每次请求都手动添加了
	  config.headers.Authorization = token
	}
	return config
  },
  err => {
	return Promise.reject(err)
  }
);
axios.interceptors.response.use(
  response => {
	let token = store.state.user.token;
	if (!token || (response.data.state === "false"&&response.data.msg == '未登录')) {
	  window.location.href = 'http://68.202.4.5:8101/login?returnURL='+window.location.href.replace(window.location.search,'');
	  return response;
	} else {
	  return response;
	}
  },
  error => {
	console.log(error);
  }
);

//<--------------------------------------------------图表------------------------------------------------------------>
//图表页面顶部列
export const apiTopList = (chooseDate) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/caseInfoTheme/countShow?date=' + chooseDate,
		//  transformRequest : [data => Qs.stringify(data)],
		//  data : param,
	});
};

//时间柱状图
export const apiCaseBar = (chooseDate, type, scopeTime, barType) => {
	let diy_url = '';
	if (barType === 1) {
		diy_url = type === 1 ? baseURL + xzName + '/caseInfoTheme/countTimes?beginTime=' + chooseDate[0] + '&endTime=' + chooseDate[1] : baseURL + xzName + '/caseInfoTheme/countTimes?scopeTime=' + scopeTime;
	} else if (barType === 2) {
		diy_url = type === 1 ? baseURL + xzName + '/caseInfoTheme/countCaseTypes?beginTime=' + chooseDate[0] + '&endTime=' + chooseDate[1] : baseURL + xzName + '/caseInfoTheme/countCaseTypes?scopeTime=' + scopeTime;
	}
	return axios({
		method: 'post',
		url: diy_url
		//  transformRequest : [data => Qs.stringify(data)],
		//  data : param,
	});
};
//案件柱状图
export const apiTypeBar = (chooseDate, type, scopeTime) => {
	return axios({
		method: 'post',
		url: type === 1 ? baseURL + xzName + '/caseInfoTheme/countCaseTypes?beginTime=' + chooseDate[0] + '&endTime=' + chooseDate[1] : baseURL + xzName + '/caseInfoTheme/countCaseTypes?scopeTime=' + scopeTime,
		//  transformRequest : [data => Qs.stringify(data)],
		//  data : param,
	});
};

export const apiRanTime = (scopeTime) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/caseInfoTheme/timeRank?scopeTime=' + scopeTime,
		//  transformRequest : [data => Qs.stringify(data)],
		//  data : param,
	});
};


export const apiRanType = (scopeTime) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/caseInfoTheme/caseTypeRank?scopeTime=' + scopeTime,
		//  transformRequest : [data => Qs.stringify(data)],
		//  data : param,
	});
};

export const apiCountAreas = (scopeTime, chooseDate, type) => {
	return axios({
		method: 'post',
		url: type === 1 ? baseURL + xzName + '/caseInfoTheme/countAreas?scopeTime=' + scopeTime : baseURL + xzName + '/caseInfoTheme/countAreas?beginTime=' + chooseDate[0] + '&endTime=' + chooseDate[1],
		//  transformRequest : [data => Qs.stringify(data)],
		//  data : param,
	});
};

export const apiCountWords = (scopeTime, chooseDate, type) => {
	return axios({
		method: 'post',
		url: type === 1 ? baseURL + xzName + '/caseInfoTheme/countWords?scopeTime=' + scopeTime : baseURL + xzName + '/caseInfoTheme/countWords?beginTime=' + chooseDate[0] + '&endTime=' + chooseDate[1],
	});
};


export const apiCountTypeRank5 = (scopeTime, chooseDate, type) => {
	return axios({
		method: 'post',
		url: type === 1 ? baseURL + xzName + '/caseInfoTheme/countTypeRank5?scopeTime=' + scopeTime : baseURL + xzName + '/caseInfoTheme/countTypeRank5?beginTime=' + chooseDate[0] + '&endTime=' + chooseDate[1],
		//  transformRequest : [data => Qs.stringify(data)],
		//  data : param,
	});
};


//<--------------------------------------------------人员列表------------------------------------------------------------>
//人员列表接口
export const apiPersonList = (param, index, size) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/caseInfoTheme/personPage?pageIndex=' + index + '&pageSize=' + size,
		transformRequest: [data => Qs.stringify(data)],
		data: param,
	});
};
//人员列表-人详情
export const apiPersonListPersonDetail = (sfzh) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/caseInfoTheme/personInfoDetail?sfzh=' + sfzh,
	});
};
//人员列表-案详情
export const apiPersonListCaseDetail = (sfzh, pages, sizes) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/caseInfoTheme/personCaseDetails?sfzh=' + sfzh + '&pageIndex=' + pages + '&pageSize=' + sizes,
	});
}

//<--------------------------------------------------案件列表------------------------------------------------------------>
//案件列表接口
export const apiCaseList = (param, index, size) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/caseInfoTheme/casePage?pageIndex=' + index + '&pageSize=' + size,
		transformRequest: [data => Qs.stringify(data)],
		data: param,
	});
};
//案件列表-人详情
export const apiCaseListPersonDetail = (ajbh, pages, sizes) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/caseInfoTheme/casePersonDetails?ajbh=' + ajbh + '&pageIndex=' + pages + '&pageSize=' + sizes,
	});
};
//案件列表-案详情
export const apiCaseListCaseDetail = (ajbh) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/caseInfoTheme/caseDetail?ajbh=' + ajbh,
	});
};

//<--------------------------------------------------警情案接口------------------------------------------------------------>
export const apiCaseTopList = (date) => {
	return axios({
		method: 'get',
		url: baseURL + '/jqa/alarmTrend/pcTop?date=' + date
	});
};
export const apipoliceTopList = (date) => {
	return axios({
		method: 'get',
		url: baseURL + '/jqa/caseTrend/ajTop?date=' + date
	});
};

export const apiCaseInfo = (startDate, endDate) => {
	return axios({
		method: 'get',
		url: baseURL + '/jqa/alarmTrend/byfileType?startDate=' + startDate + '&endDate=' + endDate + '&fileType=jqlb&jqqybh=&jqdwbh=&fkdwbh=&cjdwbh='
	})
}
export const apiCasePieInfo = (startTime, endTime) => {
	return axios({
		method: 'get',
		url: baseURL + '/jqa/alarmTrend/getGroupByArea?field=JJSL&startDate=' + startTime + '&endDate=' + endTime + '&jjdw=&cjdw=&ab=&jjfs=&cljg=&jqlb=&fxxs='
	})
}
export const apiCaseTrend = (date, type) => {
	return axios({
		method: 'get',
		url: baseURL + '/jqa/alarmTrend/getBy' + type + '?date=' + date + '&field=JJSL&jjdwbh=&cjdwbh='
	});
};

export const apiPoliceInfo = (startDate, endDate) => {
	return axios({
		method: 'get',
		url: baseURL + '/jqa/caseTrend/byfileType?fileType=ab&dmlb=B_ASJ_XZAB&startDate=' + startDate + '&endDate=' + endDate + '&caseDutyArea=&fillinOrganization=&handleOrgan=&caseLabel='
	});
};
export const apiPolicePieInfo = (startTime, endTime) => {
	return axios({
		method: 'get',
		url: baseURL + '/jqa/caseTrend/getGroupByfield?field=AJSL&startDate=' + startTime + '&endDate=' + endTime + '&fieldGroup=HANDLE_ORGAN&grade=1&deptCode='
	});
};

export const apiPoliceTrend = (date, type) => {
	return axios({
		method: 'get',
		url: baseURL + '/jqa/caseTrend/getBy' + type + '?date=' + date + '&field=AJSL&caseDutyArea=&fillinOrganization=&handleOrgan='
	});
};

//<-------------------------------------------------------重点人员------------------------------------------------------->
export const apiKeyPerson = (param, index, size) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/emphasisPerson/keyPerson?pageIndex=' + index + '&pageSize=' + size,
		transformRequest: [data => Qs.stringify(data)],
		data: param,
	});
};

//重点人员列表-人详情
export const apikeyPersonDetail = (sfzh) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/emphasisPerson/keyPersonDetail?sfzh=' + sfzh,
	});
};
//重点人员列表-轨迹详情
export const apikeyLocalDetail = (sfzh, pages, sizes) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/emphasisPerson/keyPersonTrack?sfzh=' + sfzh + '&pageIndex=' + pages + '&pageSize=' + sizes,
	});
};

//<-------------------------------------------------------人案应用------------------------------------------------------->
// 人案应用-嫌疑人分析
export const searchSuspects = (param, index, size) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/personCase/findXyr?pageIndex=' + index + '&pageSize=' + size,
		transformRequest: [data => Qs.stringify(data)],
		data: param,
	});
}

// 人案应用-犯罪人员作案分析
export const searchAppCase = (param, index, size) => {
	return axios({
		method: 'post',
		url: baseURL + xzName + '/personCase/findAj?pageIndex=' + index + '&pageSize=' + size,
		transformRequest: [data => Qs.stringify(data)],
		data: param,
	});
}




//<-------------------------------------------------------词云(搜索参数)------------------------------------------------------->
export const getWordCloud = (name) => {
  return axios({
	method: 'get',
	url: baseURL + xzName + '/codeDict/getDict?name='+ name
  });
}



